package com.jctrip.hotel.source.xxl.cnbe.thread;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.model.CnBooking.IdentityInfoDTO;
import com.jctrip.hotel.source.service.CNBooking.CNBookingTaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

/**
 * @Author：Haruhi
 * @description:
 * @Date：2023/9/18 10:23
 * @Package：com.jctrip.hotel.source.xxl.cnbe.thread
 * @Project：hotel-main
 */
@Slf4j
public class SyncCNBEXgAmInfoTaskThread implements Runnable{

    private final IdentityInfoDTO infoDTO;

    public SyncCNBEXgAmInfoTaskThread(IdentityInfoDTO infoDTO) {
        this.infoDTO = infoDTO;
    }

    @Override
    public void run() {
        RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);
        CNBookingTaskService cnBookingTaskService = BeanContext.getApplicationContext().getBean(CNBookingTaskService.class);

        while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_CNBE_XG_AM_INFO_LIST) > 0) {
            try {
                String hotelId = (String) redisUtil.rightPop(RedisKeyConstant.HOTEL_CNBE_XG_AM_INFO_LIST);
                if (StringUtils.isBlank(hotelId)) {
                    return;
                }
                String lang = "EN";
                infoDTO.setLang(lang);
                cnBookingTaskService.syncCNBEXgAmInfoTask(hotelId, infoDTO);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
